package com.sky.aspect;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

@Aspect
@Component
public class CacheCleanAspect {

    @Autowired
    private RedisTemplate redisTemplate;

    @AfterReturning("execution(* com.sky.controller.admin.DishController.*(..))")
    public void cleanCacheAdvice() {
        // 清理所有以'dish'开头的键
        Set keys = redisTemplate.keys("dish*");
        if (keys != null && !keys.isEmpty()) {
            redisTemplate.delete(keys);
        }
    }
}

